<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../Css/btn.css">
    <link rel="stylesheet" href="../Css/addRefund.css">
    <link rel="stylesheet" href="../bsp/css/bootstrap.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/c/font_3911564_ynvs5zhem7p.css">
</head>

<body>

    <div class="rightmain1">
        <div>
            <div>新增回款</div>
            <div>
                <button type="submit" class="btn1 tijiaoabocun" onclick="xzcontract()"><span
                        class="iconfont icon-export tijiaoabocun"></span>提交审核</button>
                <button type="submit" class="btn1 " onclick="xzcontract()" id="baocunbtn1"><span
                        class="iconfont icon-export"></span>保存</button>
                <button class="btn1"><a href="../refund/reManage.html"><span class="iconfont icon-export"></span>返回</a>
                </button>
            </div>
        </div>
    </div>


    <div class="jibenxingxi">
        <div><span class="iconfont icon-liebiao spanhk"></span>回款信息</div>
        <form action="">
            <ul>
                <li class="rili">
                    <!-- <div class="rili"> -->
                    <span class="ispanWidth">合同日期：</span>
                    <div><input type="date" id="contract_day1"></div>
                    <!-- </div> -->
                    <!-- <span class="ispanWidth"><span>*</span>回款日期：</span><input type="date" value="" id="payment_day1"> -->
                </li>
                <li><span class="ispanWidth"><span>*</span>客户名称：</span>
                    <input type="text" value="" id="Client_name1" data-toggle="modal" data-target="#myModal">
                    <Span class="iconfont icon-sousuoxiao spanwz"></Span>
                    <!-- Modal -->
                    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                            aria-hidden="true">&times;</span></button>
                                    <h4 class="modal-title" id="myModalLabel">客户选框</h4>
                                </div>
                                <div class="modal-body">
                                    <table>
                                        <div>
                                            <select name="hetongbianhao" id="">
                                                <option value="">111</option>
                                            </select>
                                            <input type="text" placeholder="请输入内容">
                                            <button type="button">查询</button>
                                            <button type="reset">重置</button>
                                        </div>
                                        <thead>
                                            <tr>
                                                <th>客户名称</th>
                                                <th>客户标签</th>
                                                <th>客户类型</th>
                                                <th>主要联系人</th>
                                                <th>手机号码</th>
                                            </tr>
                                        </thead>
                                        <tbody class="DataShow"></tbody>
                                    </table>
                                    <!-- 分页 -->
                                    <div class="modal-navigation"></div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn1 btn-default" data-dismiss="modal">关闭</button>
                                    <button type="button" class="btn1 btn-default" data-dismiss="modal">确定</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </li>
                <li><span class="ispanWidth"><span>*</span>合同编号：</span><input type="text" value=""
                        id="contract_number1">
                </li>
                <li><span class="ispanWidth"><span>*</span>回款金额（万元）：</span><input type="text" value=""
                        id="payment_amount1"></li>
                <li><span class="ispanWidth">回款期次：</span><input type="text" value="" id="payment_period1"></li>
                <li><span class="ispanWidth"><span>*</span>付款方式：</span><input type="text" value="" id="payment_method1">
                </li>
                <li><span class="ispanWidth"><span>*</span>银行：</span><input type="text" value="" id="bank1"></li>
                <li><span class="ispanWidth"><span>*</span>账号：</span><input type="text" value="" id="account"></li>
                <li><span class="ispanWidth"><span>*</span>是否逾期：</span><input type="text" value="" id="isOverdue1">
                </li>
                <li><span class="ispanWidth">逾期天数：</span><input type="text" value="" id="Overdue1"></li>
                <li><span class="ispanWidth">备注：</span><input type="text" value="" id="note1"></li>
            </ul>
        </form>
    </div>




    <script src="../js/jquery-3.6.3.js"></script>
    <script src="../bsp/js/bootstrap.js"></script>
    <script src="../js/database.js"></script>
    <script src="../js/contractManage.js"></script>
    <script>




        // window.onload = function () {
        //     displaytableDatakh();
        //     hqidr();
        // }
        $(document).ready(function () {
            displaytableDatakh();
            hqidr();
        })


        var idxh;
        //添加
        function xzcontract() {
            addContractID();
            // $(".tijiaoabocun").click(function () {
            let payment_day1 = $("#payment_day1").val();
            let Client_name1 = cmval;
            let contract_number1 = $("#contract_number1").val();

            let payment_amount1 = $("#payment_amount1").val();
            let payment_period1 = $("#payment_period1").val();
            let payment_method1 = $("#payment_method1").val();
            let bank1 = $("#bank1").val();
            let account1 = $("#account1").val();
            let isOverdue1 = $("#isOverdue1").val();
            let Overdue1 = $("#Overdue1").val();
            let note1 = $("#note1").val();
            addContract(idxh, contract_number1, "", "", Client_name1, "", "", "", "", "", "", "", "",
                payment_day1, payment_period1, payment_method1, payment_amount1, isOverdue1, bank1, account1, isOverdue1, Overdue1, note1)
            // asyncLocalStory("contract");
            asyncLocalStory();
            // })

            for (let i = 0; i < localStorage.length; i++) {
                console.log(localStorage.key(i));
            }

        }


        //添加id
        function addContractID() {

            //自增流水号
            let idzz = 0;

            db.contract.forEach(e => {
                if (idzz <= e.id) {
                    idzz = e.id;
                }
                idzz++;
            });
            console.log(idzz);
            idxh = idzz;

        }



        //motaikuang
        function displaytableDatakh() {

            $("DataShow").html('');
            // 文档碎片
            let fragment1 = document.createDocumentFragment();
            for (let i = 0; i < db.connection.length; i++) {
                // console.log(db.contract[0]);
                let tr = document.createElement("tr");

                tr.innerHTML = `
                    <td data-id=${db.connection[i].id} class="djuanze">${db.connection[i].name}</td>
                    <td>${db.connection[i].customer_label}</td>
                    <td>${db.connection[i].type}</td>
                    <td>${db.connection[i].linkman}</td>
                    <td>${db.connection[i].phone_number}</td>
                         `;

                fragment1.appendChild(tr);

            }

            $(".DataShow").append(fragment1);

        }


        var cmval;
        var idd;
        function hqidr() {
            let cn;
            // var cmval;
            $(".DataShow").on("click", ".djuanze", function (e) {
                idd = Number($(e.target).attr("data-id"));
                // console.log(idd);
                cn = db.connection[idd - 1].name;
                $("#Client_name1").val(cn);
                cmval = $("#Client_name1").val();

            });
        }

    </script>
</body>

</html>